home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / sfit108.zip / DLL / EXPBUILD.C < prev    next >
C/C++ Source or Header  |  1994-11-22  |  4KB  |  119 lines

  1. #define INCL_WIN
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <os2.h>
  7. #include <float.h>
  8. // the standard number of data columns
  9. #define STDCOL 5
  10. #define XSLOT 0
  11. #define YSLOT 1
  12. #define CALCSLOT -3
  13. #define BESTSLOT -2
  14. #define FLAGSLOT -1
  15.  
  16. /* static data and parameters */
  17. static double *data;                    /* start of complete data array  */
  18.  
  19. /* The data is all in a contigous block starting with datx then daty followed by
  20.  * zero or more additional data columns as read in from the data file. The last
  21.  * three slots are: datt , the current best results and the flag array. 
  22.  * Each point not in an exclusion zone has its corresponding flag TRUE. 
  23.  */
  24.  
  25.  
  26. static double *datx;                    /* x data read in from data file */
  27. static double *daty;                    /* y data read in from data file */
  28. static double *datt;                    /* generated data */
  29. static int Ndat;                        /* number of data points */
  30. static char firsttime;
  31. static double **Ptr;                    /* pointer to parameter pointer array */
  32.  
  33. struct info_line
  34.    {
  35.    char *line;
  36.    };
  37.  
  38. /*****************************************************************************/
  39. /* Do not modify any code not enclosed by this and the end banner            */
  40. /*****************************************************************************/
  41.  
  42. /* the next two values are compared to values passed by the program as check */
  43. /* NADD is the number of additional data columns required for this function  */
  44. /* NPARAM is the number of parameters required by this function              */
  45.  
  46. #define NADD 0              
  47. #define NPARAM  4
  48.  
  49. /* edit the following lines or add and delete new lines */ 
  50. static struct info_line dll_info[] = { 
  51.    "This function calculates an exponential buildup.",
  52.    "It requires 3 parameters as follows:",
  53.    "P1 is the starting position of the exponential along the x axis.",
  54.    "P2 is the amplitude of exponential.",
  55.    "P3 is the buildup constant.", 
  56.    "P4 is a constant y shift",
  57.    NULL};
  58.    
  59. VOID EXPENTRY fitfunc(void)
  60.    {
  61.    int i;
  62.    double tau;
  63.    double amplitude;
  64.    double position;
  65.    double y_shift;
  66.  
  67.    /* The next section is executed the first time through only */
  68.    /* so put any initialization code in here                   */
  69.    if (firsttime) 
  70.       {
  71.       /* Mask off all floating point exceptions */
  72.       _control87(MCW_EM,MCW_EM);
  73.       firsttime = FALSE;
  74.       }
  75.  
  76.    /* give parameters more meaningful names  */
  77.    position = *Ptr[1];
  78.    amplitude = *Ptr[2];
  79.    tau = *Ptr[3];
  80.    y_shift = *Ptr[4];
  81.  
  82.    /* This is the main loop that calculates the function datt[] */
  83.    /* for all data points. Put your function in the loop body   */ 
  84.    for (i = 0;i < Ndat;i++)
  85.       {
  86.       datt[i] = amplitude * ( 1 - exp(-(datx[i] - position) / tau)) + y_shift;
  87.       }
  88.    }
  89.  
  90. /*****************************************************************************/
  91. /* Do not modify any code not enclosed by this and the start banner          */
  92. /*****************************************************************************/
  93.  
  94.  
  95.  
  96. char EXPENTRY init_dll_globals(int N,int mb,int NP,double *dat,double *p[])
  97.    {
  98.    /* set globals */
  99.    firsttime = TRUE;
  100.    Ndat = N;
  101.    if (NADD != mb - STDCOL) return -1;
  102.    if (NPARAM != NP) return -2;
  103.    /* set array pointers */
  104.    data = dat;
  105.    daty = dat + N;
  106.    datx = dat;
  107.    datt = dat + (mb + CALCSLOT) * N;     /* the calculated data goes into the third last slot */
  108.    /* set parameter pointers */
  109.    Ptr = p;
  110.    return 0;
  111.    }
  112.  
  113. struct info_line * EXPENTRY get_dll_info(void)
  114.    {
  115.    /* return pointer to array of info strings set up above */
  116.    return dll_info; 
  117.    }
  118.  
  119.